<%@ page import="com.hkpickup.character.*" language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Encoding Converter</title>
</head>
<% 
String outputDefault="parse error!";

String targetBtn = request.getParameter("target_btn");
String inChar=request.getParameter(targetBtn);
String inDebug=request.getParameter("input_debug");
String outputDebug = inChar+ " "+ targetBtn;
String outChar=null;

byte[] transform;
String utf8Hex=outputDefault;
String utf16Hex=outputDefault;
String utf16BigHex=outputDefault;
String utf16LittleHex=outputDefault;
String big5Hex=outputDefault;
String big5url=outputDefault;
String big5HkscsHex=outputDefault;
String asciiHex=outputDefault;
String gsmHex=outputDefault;


if (targetBtn!=null && !targetBtn.equals("input_char")){

	/* input is text */ 
	String inEncode = ""; 
	if (targetBtn.equalsIgnoreCase("input_utf8")) {
		inEncode = "UTF-8";
	}else if (targetBtn.equalsIgnoreCase("input_utf16")) {
		inEncode = "UTF-16";
	}else if (targetBtn.equalsIgnoreCase("input_utf16le")) {
		inEncode = "UTF-16LE";	
	}else if (targetBtn.equalsIgnoreCase("input_utf16be")) {
		inEncode = "UTF-16BE";	
	}else if (targetBtn.equalsIgnoreCase("input_big5")) {
		inEncode = "BIG5";	
	}else if (targetBtn.equalsIgnoreCase("input_big5url")) {
		inEncode = "BIG5";	
	}else if (targetBtn.equalsIgnoreCase("input_big5hkscs")) {
		inEncode = "BIG5-HKSCS";			
	}else if (targetBtn.equalsIgnoreCase("input_ascii")) {
		inEncode = "ISO-8859-1";	
	}else if (targetBtn.equalsIgnoreCase("input_gsm")) {
		inEncode = "ISO-8859-1";	
	}
	
	String inHexStr=inChar.replaceAll(" ", "");
	
	outChar = new String (Utility.toBytes(inChar), inEncode);	
}else{
	outChar = inChar;
}

if (outChar!=null){

	utf8Hex = Utility.toHexString(outChar.getBytes("UTF-8"));
	utf16Hex = Utility.toHexString(outChar.getBytes("UTF-16"));
	utf16BigHex = Utility.toHexString(outChar.getBytes("UTF-16BE"));
	utf16LittleHex = Utility.toHexString(outChar.getBytes("UTF-16LE"));
	big5Hex = Utility.toHexString(outChar.getBytes("BIG5"));
	big5url = Utility.toHexString(outChar.getBytes("BIG5"));
	big5HkscsHex = Utility.toHexString(outChar.getBytes("BIG5-HKSCS"));
	asciiHex = Utility.toHexString(outChar.getBytes("ISO-8859-1"));
	gsmHex = asciiHex;
}
%>
<body>
	<form method="post" action="./encodingConverter.jsp" name="ec">
	
		<table>
			<tbody>
				<tr>
					<th colspan="3"><font size="5">Unicode Content
							Converter</font>
					</th>
				</tr>
				<tr>
					<td width="30%">SERVLET INIT. TIMESTAMP</td>
					<td width="70%">2011-07-20 14:56:28 +0800</td>
				</tr>
				<tr>
					<td width="30%">Characters</td>
					<td width="70%"><input type="text" name="input_char" value="<%=outChar %>"
						size="85"><input type="button" name="con_char" size="10"
						onclick="javascript:convert(&quot;input_char&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">UTF-8 code units</td>
					<td width="70%"><input type="text" name="input_utf8" value="<%=utf8Hex %>"
						size="85"><input type="button" name="con_utf8" size="10"
						onclick="javascript:convert(&quot;input_utf8&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">UTF-16 code units</td>
					<td width="70%"><input type="text" name="input_utf16"
						value="<%=utf16Hex %>" size="85"><input type="button" name="con_utf16"
						size="10" onclick="javascript:convert(&quot;input_utf16&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">UTF-16BE code units</td>
					<td width="70%"><input type="text" name="input_utf16BE"
						value="<%=utf16BigHex %>" size="85"><input type="button" name="con_utf16be"
						size="10" onclick="javascript:convert(&quot;input_utf16be&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">UTF-16LE code units</td>
					<td width="70%"><input type="text" name="input_utf16LE"
						value="<%=utf16LittleHex %>" size="85"><input type="button" name="con_utf16le"
						size="10" onclick="javascript:convert(&quot;input_utf16le&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">ASCII/Latin-1 code units</td>
					<td width="70%"><input type="text" name="input_ascii"
						value="<%=asciiHex %>" size="85"><input type="button" name="con_ascii"
						size="10" onclick="javascript:convert(&quot;input_ascii&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">GSM code units</td>
					<td width="70%"><input type="text" name="input_gsm" value=""
						size="85"><input type="button" name="con_gsm" size="10"
						onclick="javascript:convert(&quot;input_gsm&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">Big5 code units</td>
					<td width="70%"><input type="text" name="input_big5" value="<%=big5Hex %>"
						size="85"><input type="button" name="con_big5" size="10"
						onclick="javascript:convert(&quot;input_big5&quot;);"
						value="Convert">
					</td>
				</tr>
				<tr>
					<td width="30%">Big5 URL code units</td>
					<td width="70%"><input type="text" name="input_big5url" value="<%=big5url %>"
						size="85"><input type="button" name="con_big5url" size="10"
						onclick="javascript:convert(&quot;input_big5url&quot;);"
						value="Convert">
					</td>
				</tr>								
				<tr>
					<td width="30%">Big5-HKSCS code units</td>
					<td width="70%"><input type="text" name="input_big5hkscs" value="<%=big5HkscsHex %>"
						size="85"><input type="button" name="con_big5hkscs" size="10"
						onclick="javascript:convert(&quot;input_big5hkscs&quot;);"
						value="Convert">
					</td>
				</tr>				
				<tr>
					<td width="30%">Debug</td>
					<td width="70%"><input type="text" name="input_debug" value="<%=outputDebug%>"
						size="85"><input type="button" name="con_debug" size="10"
						onclick="javascript:convert("input_debug");"
						value="Convert">
					</td>
				</tr>
				<!-- 
				<tr>
					<td class="whole" colspan="3"><a href="/tools/index.jsp">Back
							to main page</a>
					</td>
				</tr>
				 -->
				<input type="hidden" name="target_btn" value="">
			</tbody>
		</table>
	</form>
	<script type="text/javascript">function convert(field_name) {
		document.getElementsByName("target_btn")[0].value = field_name;
		document.ec.submit();
		}
	</script>
	
	
</body>
</html>



